package com.example.text0926;

import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;

public class Fragment2 extends Fragment {

    private RecyclerView recyclerView;
    private Context context;
    private RecyclerView.Adapter adapter;

    private List<Map<String,Object>> list1;
//    MyService.MyBinder mybinder;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
//        return inflater.inflate(R.layout.fragment_layout2, container, false);
        View view = inflater. inflate(R.layout.rc_activity_main, container, false);

        context = getContext();
        recyclerView=view.findViewById(R.id.recyclerView);

//      String[] phonename = {"A","B","C"};
        int[] phonename = {R.drawable.p1, R.drawable.p2, R.drawable.p3};
        String[] price={"1999","2999","3999"};
        String[] config={"a","b","c"};

//        list=new ArrayList<String>();
//        for(int i =0;i<9;i++)
//        {list.add("这是第"+i+"个示例");}

//接口不能new一个对象List，所以使用类ArrayList来new
        list1=new ArrayList<Map<String, Object>>() {};
        for(int i =0;i<phonename.length;i++)
        {
            Map<String,Object> map = new HashMap<>();//Hash Map根据类型（phonename、price、config）分堆
            map.put("phonename",phonename[i]);
            map.put("price",price[i]);
            map.put("config",config[i]);

            list1.add(map);
        }

        adapter= new com.example.text0926.adapter(context,list1);
        recyclerView.setAdapter(adapter);

        LinearLayoutManager manager=new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);

//        Intent intent = new Intent(context, MyService.class);
//
//        ServiceConnection connection = new ServiceConnection() {
//            @Override
//            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
//                mybinder = (MyService.MyBinder)iBinder;
//                mybinder.todo();
//            }
//
//            @Override
//            public void onServiceDisconnected(ComponentName componentName) {
//                mybinder = null;
//            }
//        };
//
//        context.bindService(intent,connection,Context.BIND_AUTO_CREATE);
//        context.unbindService(connection);

        return view;
    }
}

